export default function newDialog(form, request, rules) {
    let dialog = reactive({
        dialogVisible: false,
        form,
        request,
        rules,
        //显示弹窗
        show: function () {
            dialog.dialogVisible = true
        },

        //校验通过，真正的处理逻辑
        doConfirm: function (request) {

        },

        //表单确认提交，校验数据并决定是否执行真正的处理逻辑
        confirm: async function () {
            if (!form.value) return
            await form.value.validate((valid, fields) => {
                if (!valid) { return }
                dialog.doConfirm(dialog.request);
            })
        },

        //关闭弹窗，清除数据
        close: function () {
            dialog.dialogVisible = false
            dialog.clearForm()
        },

        //清除数据
        clearForm: function clearForm() {
            if (!form.value) return
            form.value.resetFields()
        }
    })
    return dialog;
}
